package com.cupk.carManageMaster.core.serviceImpl;

import com.cupk.carManageMaster.core.service.ProductTokenService;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

/**
 * 名称ProductTokenServiceImpl
 * 描述ProductToken
 *
 * @version 1.0
 * @author:wanghao
 * @datatime:2023,06,01,15,37
 */
@Service
public class ProductTokenServiceImpl implements ProductTokenService {

    @Override
    public Map<String, String> productToken(String key, String value) {

        Jedis jedis = new Jedis("r-bp1fckprlkd7o7t322pd.redis.rds.aliyuncs.com", 6379);  //指定Redis服务Host和port
        jedis.auth("Wh314159*"); //如果Redis服务连接需要密码，制定密码
        String key_value = jedis.get(key);
        Map<String, String> infoMap = new HashMap<String, String>();
        //访问Redis服务
        //使用完关闭连接
        if (key_value == null) {
            //将登陆的信息保存如redis
            //stringRedisTemplate.opsForValue().set(key, value);
            jedis.set(key, value);
            infoMap.put("token", value);
        } else
            infoMap.put("token", key_value);
        //设置token有效的时间 100min
        jedis.expire(key, 60000);
        //stringRedisTemplate.expire(key, 6000, TimeUnit.SECONDS);
        jedis.close();
        return infoMap;
    }
}
